﻿Public Class FrmMain
    Dim DB As ClsDatabase
    Dim JobChanged As Boolean = False
    Dim CurrentJobId As Long = 0

    Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DB = New ClsDatabase
        DB.InitDB()
        loadJobs()
    End Sub

    ''' <summary>
    ''' Retrievs the jobs from the database and lists them in the listview
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub loadJobs()
        Dim Jobs As Collection
        Dim GrpActions As ListViewGroup
        Dim GrpJobs As ListViewGroup
        Dim LViewItem As ListViewItem
        LViewJobs.Items.Clear()
        LViewJobs.Groups.Clear()
        GrpActions = LViewJobs.Groups.Add("actions", "Actions")

        LViewItem = New ListViewItem
        LViewItem.Text = "Add job"
        LViewItem.Tag = "addjob"
        LViewItem.ImageIndex = 0
        LViewItem.SubItems.Add("Adds a new Job")
        LViewItem.Group = GrpActions
        LViewJobs.Items.Add(LViewItem)

        LViewItem = New ListViewItem
        LViewItem.Text = "Run job"
        LViewItem.Tag = "runjob"
        LViewItem.ImageIndex = 0
        LViewItem.SubItems.Add("Runs a job")
        LViewItem.Group = GrpActions
        LViewJobs.Items.Add(LViewItem)

        LViewItem = New ListViewItem
        LViewItem.Text = "Delete job"
        LViewItem.Tag = "deletejob"
        LViewItem.ImageIndex = 0
        LViewItem.SubItems.Add("Deletes a job")
        LViewItem.Group = GrpActions
        LViewJobs.Items.Add(LViewItem)

        GrpJobs = LViewJobs.Groups.Add("jobs", "Jobs")
        Jobs = DB.getJobs()
        For i = 1 To Jobs.Count
            Dim Job(1) As String
            Job = Jobs.Item(i)
            LViewItem = New ListViewItem
            LViewItem.Text = Job(1)
            LViewItem.Tag = Job(0)
            LViewItem.ImageIndex = 1
            LViewItem.Group = GrpJobs
            LViewItem.SubItems.Add("Job mode")
            LViewJobs.Items.Add(LViewItem)
        Next
    End Sub

    Private Sub MnuViewSmall_Click(sender As Object, e As EventArgs) Handles MnuViewSmall.Click
        LViewJobs.View = View.SmallIcon
    End Sub

    Private Sub MnuViewLarge_Click(sender As Object, e As EventArgs) Handles MnuViewLarge.Click
        LViewJobs.View = View.LargeIcon
    End Sub

    Private Sub MnuViewDetails_Click(sender As Object, e As EventArgs) Handles MnuViewDetails.Click
        LViewJobs.View = View.Details
    End Sub

    Private Sub MnuViewList_Click(sender As Object, e As EventArgs) Handles MnuViewList.Click
        LViewJobs.View = View.List
    End Sub

    Private Sub MnuViewTile_Click(sender As Object, e As EventArgs) Handles MnuViewTile.Click
        LViewJobs.View = View.Tile
    End Sub

End Class
